package cn.itcast.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @Author: zhaojie
 * @Date: Created in 14:15 2018/7/30
 * @Description:
 */
@Controller
public class FileUploadController {

    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    @ResponseBody
    public String upload(@RequestParam("photo") MultipartFile photo) throws IOException {
        byte[] bytes = photo.getBytes();
        File fileSave = new File(photo.getOriginalFilename());
        FileCopyUtils.copy(bytes, fileSave);
        return fileSave.getAbsolutePath();
    }

    @GetMapping("/get")
    @ResponseBody
    public String get(){
        return "s";
    }
}
